﻿@model List<UniversityRatingSystem.Models.ColumnDataInViewModel>
@using UniversityRatingSystem.Models
@{
    ViewBag.Title = "EditDocument";
    Layout = "~/Views/ApplicationLogic/_userLayout.cshtml";
}

<h2>EditDocument</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Document</h4>
        <hr />

        <div class="form-group">
            <label class="control-label col-md-2">@ViewBag.doc.Title</label>
            <div class="col-md-10">
                @ViewBag.doc.Title
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-2">@ViewBag.doc.Group.Name</label>
            <div class="col-md-10">
                @ViewBag.doc.Group.Name
            </div>
        </div>

        <table class="table table-striped table-hover">
            <tr>
                <th>Студенты</th>
                @foreach(var item in Model)
                {
                    <th> @item.Name </th>
                }
            </tr>
            @foreach (var student in ViewBag.doc.Group.Students)
            {
                <tr>
                    <td> @(student.AspUser.LastName+" "+student.AspUser.FirstName+" "+student.AspUser.Patronymic) </td>
                    @for (int i = 1; i <= Model.Count; i++)
                    {

                        Mark mark = ((student.Marks!=null)&&(student.Marks.Count>0))?student.Marks.First(((Predicate<Mark>)(e => e.MarkId==i))):null;
                        if (mark == null)
                        {
                            <td>0</td>
                        }
                        else
                        {
                            <td>@Html.EditorFor(m => mark.Ball)</td>
                        }
                    }
                </tr>
            }
        </table>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
